﻿using System;
using Newtonsoft.Json;
using XiaWorld;

namespace WritingBooks
{
    // Token: 0x020006FD RID: 1789
    [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
    public class CommandWrite : Command
    {
        // Token: 0x170003F3 RID: 1011
        // (get) Token: 0x0600300A RID: 12298
        public override int GridKey
        {
            get
            {
                if (this.item != null)
                {
                    return this.item.Key;
                }
                return base.GridKey;
            }
        }

        protected override void OnInit(params object[] objs)
        {
            base.OnInit(objs);
            this.kind = (g_emItemLable)objs[0];
            this.item = (objs[1] as ItemThing);
            this.ItemId = this.item.ID;
            this.item.Lock.Lock(this, 1);
            this.EId = (string)objs[2];
        }

        public override void OnAfterLoad()
        {
            this.item = (ThingMgr.Instance.FindThingByID(this.ItemId) as ItemThing);
        }

        protected override void OnFinished(bool did)
        {
            if (this.item != null)
            {
                this.item.Lock.UnLockAllByOwner(this);
            }
        }

        protected override bool CheckRemoveAble()
        {
            return this.item == null;
        }

        protected override bool CouldBeFind(Npc npc)
        {
            Npc npc2 = base.OwnerThing as Npc;
            return !npc2.IsCorpse && !npc2.IsDeath && base.CouldBeFind(npc) && this.item != null && npc.map.CheckPath(npc, this.item.Key, g_emPathEndMode.Touch, false, true) > 0;
        }

        [JsonProperty]
        public int ItemId;

        [JsonProperty]
        public g_emItemLable kind;

        [JsonProperty]
        public string EId;

        private ItemThing item;
    }
}
